package main

import (
	"fmt"
	"sort"
)

//#link: https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/
func main() {
	ranges := [][]int{{1, 2}, {3, 4}, {5, 6}}
	left, right := 2, 5
	fmt.Println(isCovered(ranges, left, right))
	ranges = [][]int{{1, 10}, {10, 20}}
	left, right = 21, 21
	fmt.Println(isCovered(ranges, left, right))
	ranges = [][]int{{50, 50}}
	left, right = 1, 50
	fmt.Println(isCovered(ranges, left, right))
}

func isCovered(ranges [][]int, left int, right int) bool {
	sort.Slice(ranges, func(i, j int) bool {
		return ranges[i][0] < ranges[j][0]
	})
	//终止条件为left小于right
	for _, num := range ranges {
		for left >= num[0] && left <= num[len(num)-1] {
			left++
		}
	}
	return left > right
}
